<template>
    <view>
        <u-navbar :is-back="true" :title="navbar.title" :background="navbar.background">
        </u-navbar>
        <view class="u-page">
            <view class="wrap">
                <u-form label-width="150">
                    <#list Fields as field>
                        <#if field.editShow == true>
                            <#if field.selectUrl??>
                                <u-form-item :label="$t('${moduleName}.${objectName}.${field.javaField!''}')" prop="${field.javaField!''}">
                                    <u-input disabled v-model="${objectName}Info.${field.javaField!''}" type="text" :placeholder="$t('${moduleName}.${objectName}.${field.javaField!''}')"
                                             @click="${field.javaField!''}Click"></u-input>
                                    <z-multi-choose activeColor="red" :selectedData="${objectName}Info.${field.javaField!''}List" idKey="${field.selectKey!''}"
                                                    showKey="${field.selectValue!''}" :list="${field.javaField!''}List" :show="${field.javaField!''}SelectShow" @maskTouch="cancle"
                                                    @sure="${field.javaField!''}Confirm" @cancle="${field.javaField!''}Cancle"></z-multi-choose>
                                </u-form-item>
                            <#else>
                                <u-form-item :label="$t('${moduleName}.${objectName}.${field.javaField!''}')" prop="${field.javaField!''}">
                                    <u-input ref="${field.javaField!''}" v-model="${objectName}Info.${field.javaField!''}" type="text"></u-input>
                                </u-form-item>
                            </#if>
                        </#if>
                    </#list>
                </u-form>
                <u-button shape="circle" @click="saveOrUpdate">{{ $t('system.submit') }}</u-button>
            </view>
        </view>
        <footerBar></footerBar>
    </view>
</template>

<script>
    import request from "utils/request.js"
    import cascader from '@/components/yunmiao-cascader/yunmiao-cascader.vue';
    import ldSelect from '@/components/ld-select/ld-select.vue';
    import zMultiChoose from '@/components/z-multi-choose/z-multi-choose.vue';
    export default {
        components: {
            cascader,
            ldSelect
        },
        data() {
            return {
                ${objectName}Info: {

                },
                <#list Fields as field>
                <#if field.editShow == true>
                <#if field.selectUrl??>
                ${field.javaField!''}SelectShow: false,
                ${field.javaField!''}List: [],
                </#if>
                </#if>
                </#list>
                navbar: {
                    title: this.$t('${moduleName}.${objectName}.${objectName}Edit'),
                    background: {
                        backgroundColor: '#001f3f',
                        backgroundImage: 'linear-gradient(45deg, rgb(28, 187, 180), rgb(141, 198, 63))'
                    }
                }
            }
        },
        onLoad(data) {
            this.${objectName}Info = JSON.parse(data.${objectName}Info)
            <#list Fields as field>
            <#if field.editShow == true>
            <#if field.selectUrl??>
            this.get${field.javaField!''}List();
            </#if>
            </#if>
            </#list>

        },
        methods: {
            <#list Fields as field>
            <#if field.editShow == true>
            <#if field.selectUrl??>
            this.get${field.javaField!''}List(){
                request({
                    url: '${field.selectUrl??}',
                    method: 'post',
                    params: {}
                }).then(response => {
                    this.${field.javaField!''}List = response.data
                })
            },
            ${field.javaField!''}Click() {
                this.${field.javaField!''}SelectShow = true
            },
            ${field.javaField!''}Confirm(data) {
                this.${objectName}Info.${field.javaField!''} = data.idArr.toString()
                this.${objectName}Info.${field.javaField!''}Names = data.textArr.toString()
                this.${field.javaField!''}SelectShow = false
            },
            ${field.javaField!''}Cancle() {
                this.${field.javaField!''}SelectShow = true
            },
            </#if>
            </#if>
            </#list>
            // 保存或更新
            saveOrUpdate() {
                var url = '/${moduleName}/${objectName}/insert';
                if (this.${objectName}Info.${tableConfiguration.keyProperty}) {
                    url = '/${moduleName}/${objectName}/update';
                }
                request({
                    url: url,
                    method: 'post',
                    data: this.${objectName}Info
                }).then(response => {
                    this.$u.route({
                        url: "/pages/${moduleName}/${vuePath}/${vuePath}-list"
                    })
                })
            }
        }
    }
</script>

<style>
    .wrap {
        padding: 40rpx;
    }
</style>
